<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - FooTable</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/footable/footable.core.css" rel="stylesheet">

    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>医生列表</h5>
                </div>
                <div class="ibox-content">

                    <table class="footable table table-stripped toggle-arrow-tiny" data-page-size="8">
                        <thead>
                        <tr>

                            <th data-toggle="true">工号</th>
                            <th>姓名</th>
                            <th>科室</th>
                            <!--<th>提交时间</th>-->
                            <th data-hide="all">性别</th>

                            <th data-hide="all">年龄</th>
                            <th data-hide="all">身份证号</th>
                            <th data-hide="all">密码</th>
                            <th>操&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;作</th>
                        </tr>
                        </thead>
                        <tbody id="tbody">

                        <tr>
                            <td>12138</td>
                            <td>张飞</td>
                            <td>儿科</td>
                            <td>女</td>
                            <td>28</td>
                            <td>371522199999994545</td>
                            <td>s8sd4sa6</td>
                            <td>
                                <a data-toggle="modal" href="form_basic.html#repdoc">修改</a>&nbsp;<a href="">删除</a>
                            </td>
                        </tr>
                        </tbody>
                        <tfoot>
                        <tr>
                            <td colspan="5">
                                <ul class="pagination pull-right"></ul>
                            </td>
                        </tr>
                        </tfoot>

                    </table>
                    <a data-toggle="modal" class="btn btn-primary" href="form_basic.html#adddoc">医生注册</a>
                </div>
            </div>
        </div>
    </div>

</div>


<div id="adddoc" class="modal fade" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-6 b-r">
                        <h3 class="m-t-none m-b">注册新的医生</h3>
                        <form role="form">
                            <div class="form-group">
                                <label>姓名：</label>
                                <input id="name" type="text" placeholder="请输入用户名"  class="form-control">
                            </div>
                            <div class="form-group">
                                <label>身份证号：</label>
                                <input id="card" type="text" placeholder="请输入身份证号" class="form-control">
                            </div>
                            <div class="form-group">
                                <label>年龄：</label>
                                <input id="age" type="number" placeholder="请输入年龄" class="form-control">
                            </div>
                            <div class="form-group">
                                <label>性别：</label>
                                <select class="form-control" id="sex">
                                    <option value="0">男</option>
                                    <option value="1">女</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>科室：</label>
                                <select class="form-control" id="room">
                                    <option>请选择科室</option>
                                    <option value="儿科">儿科</option>
                                    <option value="妇科">妇科</option>
                                    <option value="男科">男科</option>
                                    <option value="外科">外科</option>
                                    <option value="内科">内科</option>
                                    <option value="五官科">五官科</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>密码：</label>
                                <input id="password" type="password" placeholder="请输入密码" class="form-control"
                                       value="123456">
                                <a style="color: red; font-size: 12px;"> *默认密码为123456</a>
                            </div>
                            <br>
                            <div>
                                <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="button" id="addDocReg" onclick="addDocRegest()">
                                    <strong>注册</strong>
                                </button>

                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<!--    <div id="repdoc" class="modal fade" aria-hidden="true">-->
<!--        <div class="modal-dialog">-->
<!--            <div class="modal-content">-->
<!--                <div class="modal-body">-->
<!--                    <div class="row">-->
<!--                        <div class="col-sm-6 b-r">-->
<!--                            <h3 class="m-t-none m-b">修改医生信息</h3>-->
<!--                            <form role="form">-->
<!--                                <div class="form-group">-->
<!--                                    <label>姓名：</label>-->
<!--                                    <input id="name" type="text" placeholder="请输入用户名" class="form-control">-->
<!--                                </div>-->
<!--                                <div class="form-group">-->
<!--                                    <label>身份证号：</label>-->
<!--                                    <input id="card" type="text" placeholder="请输入身份证号" class="form-control">-->
<!--                                </div>-->
<!--                                <div class="form-group">-->
<!--                                    <label>年龄：</label>-->
<!--                                    <input id="age" type="number" placeholder="请输入年龄" class="form-control">-->
<!--                                </div>-->
<!--                                <div class="form-group">-->
<!--                                    <label>性别：</label>-->
<!--                                    <select class="form-control" id="sex">-->
<!--                                    	<option value="0">男</option>-->
<!--                                    	<option value="1">女</option>-->
<!--                                    </select>-->
<!--                                </div>-->
<!--                                <div class="form-group">-->
<!--                                    <label>科室：</label>-->
<!--                                    <select class="form-control" id="room">-->
<!--                                    	<option>请选择科室</option>-->
<!--                                    	<option value="儿科">儿科</option>-->
<!--                                    	<option value="妇科">妇科</option>-->
<!--                                    	<option value="男科">男科</option>-->
<!--                                    	<option value="外科">外科</option>-->
<!--                                    	<option value="内科">内科</option>-->
<!--                                    	<option value="五官科">五官科</option>-->
<!--                                    </select>-->
<!--                                </div>-->
<!--                                <div class="form-group">-->
<!--                                    <label>密码：</label>-->
<!--                                    <input id="password" type="password" placeholder="请输入密码" class="form-control">-->
<!--                                    -->
<!--                                </div>-->
<!--                                <br>-->
<!--                                <div>-->
<!--                                    <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"><strong>确认修改</strong>-->
<!--                                    </button>-->
<!--                                    -->
<!--                                </div>-->
<!--                            </form>-->
<!--                        </div>-->
<!--                        -->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
<!--    </div>-->
<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/plugins/footable/footable.all.min.js"></script>
<script src="js/index.js"></script>

<!-- 自定义js -->
<script>
    $(document).ready(function () {
        getDoctor();
        $('.footable').footable();
        $('.footable2').footable();

    });

    function getDoctor() {
        $.ajax({
            async: false,
            type: "post",
            url: "/getDoctor",
            contentType: 'application/json',
            dataType: "text",
            success: function (data) {
                var result = JSON.parse(data);
                console.log(result);
                if (result.SUCCESS) {
                    list = result.RESULT;
                    console.log(list);
                    makeList(list)
                } else {
                    console.log(result.RESULT);
                }
            },
            error: function (data) {
                alert("请求失败");
            }
        });
    }


    function makeList(list) {

        var html = "";
        for (var i = 0; i < list.length; i++) {
            /**
             <tr>

             <th data-toggle="true">工号</th>
             <th>姓名</th>
             <th>科室</th>
             <!--<th>提交时间</th>-->
             <th data-hide="all">性别</th>

             <th data-hide="all">年龄</th>
             <th data-hide="all">身份证号</th>
             <th data-hide="all">密码</th>
             <th>操&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;作</th>
             </tr>
             */
            html += " <tr><td>" + list[i].number + "</td>    ";
            html += " <td>" + list[i].name + "</td>";
            html += " <td>" + list[i].room + "</td>";
            if (list.sex == 1) {
                html += " <td>" + "女" + "</td>";
            } else {
                html += " <td>" + "男" + "</td>";
            }
            html += " <td>" + list[i].age + "</td>";
            html += " <td>" + list[i].card + "</td>";
            html += " <td>" + list[i].password + "</td>";
            html += " <td><a data-toggle='modal' href='/admin-doc-rep.html?id=" + list[i].id + "'>修改</a>&nbsp;<a href='' onclick='delDoc(" + list[i].id + ")'>删除</a></td></tr>";
        }
        $('#tbody').html(html);
        console.log(html);
    }


    function delDoc(id) {
        $.ajax({
            async: true,
            type: "post",
            url: "/delDoc",
            data: JSON.stringify({id: id}),
            contentType: 'application/json',
            dataType: "text",
            success: function (data) {
                var result = JSON.parse(data);
                console.log(result);
                if (result.SUCCESS) {
                    alert(result.RESULT);
                    window.location.href = "/admin-doc.html";
                } else {
                    alert(result.RESULT);
                }
            },
            error: function (data) {
                alert("请求失败");
            }
        });

    }


    function addDocRegest() {
        var name = $("#name").val().trim();
        var password = $("#password").val().trim();
        var card = $("#card").val().trim();
        var sex = $("#sex").val().trim();
        var age = $("#age").val().trim();
        var numAge = parseInt(age);
        var phone = $("#room").val().trim();
        if (name == null) {
            alert("请输入名字！");
            return false;
        }
        if (room == null) {
            alert("科室不可为空！");
            return false;
        }
        if (card == null || card.length != 18) {
            alert("身份证不符合规范！");
            return false;
        }
        if (sex == null || (sex != 0 && sex != 1)) {
            alert("请输入性别！");
            return false;
        }
        if (age != null) {
            if (numAge < 0 && numAge >= 150) {
                alert("请输入正确年龄！");
                return false;
            }
        } else {
            alert("请输入年龄！");
            return false;
        }
        $.ajax({
            async: true,
            type: "post",
            url: "/addDoctor",
            data: JSON.stringify(getQueryData1()),
            contentType: 'application/json',
            dataType: "text",
            success: function (data) {
                var result = JSON.parse(data);
                console.log(result);
                if (result.SUCCESS) {
                    alert(result.RESULT);
                } else {
                    alert(result.RESULT);
                }
            },
            error: function (data) {
                alert("请求失败");
            }
        });

    }


    function getQueryData1() {
        var dto = {};
        if (!ifEmpty($("#name").val())) {
            dto["name"] = $("#name").val().trim();
        }
        if (!ifEmpty($("#card").val())) {
            dto["card"] = $("#card").val().trim();
        }
        if (!ifEmpty($("#room").val())) {
            dto["room"] = $("#room").val().trim();
        }
        if (!ifEmpty($("#age").val())) {
            dto["age"] = $("#age").val().trim();
        }
        if (!ifEmpty($("#sex").val())) {
            dto["sex"] = $("#sex").val().trim();
        }
        if (!ifEmpty($("#password").val())) {
            dto["password"] = $("#password").val().trim();
        }
        return dto;
    }



</script>

</body>

</html>
